package com.bwie.search.controller;

import com.alibaba.fastjson2.JSONArray;
import com.bwie.common.core.domain.Result;
import com.bwie.common.core.domain.SkuEsModel;
import com.bwie.search.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/es")
public class EsController {
    @Autowired
    private ProductService productService;

    /**
     * 批量将选中的spu下的sku信息添加到es中
     * @return
     */
    @PostMapping("/save")
    public Result esSaveProduct(@RequestBody String skuEsModelList){
        List<SkuEsModel> list = JSONArray.parseArray(skuEsModelList, SkuEsModel.class);
        productService.esSaveProduct(list);
        return Result.success();
    }

    /**
     * 根据spuId删除es中的sku信息
     * @param spuId
     * @return
     */
    @DeleteMapping("/del/{spuId}")
    public Result esDelProduct(@PathVariable Long spuId){
        productService.esDelProduct(spuId);
        return Result.success();
    }
}
